Release 10.1A: OpenEdge Development:
Java Open Clients
Updating SDOResultSet objects
![]()
To update an SDOResultSet object:
Caution: If you move the cursor from a row where you updated columns (for example, usingnext()), before you commit the column updates to the database, your column updates to that row will be lost.Transactions and concurrency control
By default, all updates that change the database occur in a transaction managed by the remote SmartDataObject. Typically, any method that updates or deletes an existing row, or that inserts a new row causes the SmartDataObject to complete a transaction for that row. Note that updating column values does not, in itself, change the database. Only row operations can actually cause a transaction to occur.
You also can extend a transaction to include modifications to multiple rows by using an SDOResultSet in Batch mode or by remotely controlling an automatic transaction, if one is available on the AppServer. For more information on Batch mode, see the "Using batch mode [extension]" section. For more information on automatic transactions, see the "Using extended transactions" section.
SmartDataObjects use optimistic concurrency control, which means records are read without a lock. Locks are acquired only for the short duration of the transaction when modifications are performed. Before updating or deleting a row, the remote SmartDataObject implementation compares the original values of the columns to their values in the database to determine if the columns were modified by another user. If a column was modified, the modification does not succeed and the transaction is rolled back. A failed update then throws an
SDOModificationException. If the SmartDataObject implementation tries to modify or delete a row that is locked, it also throws anSDOModificationException. For more information onSDOModificationException, see the "Errors and exceptions" section.Updating column values
The following methods modify a column in an SDOResultSet according to the specified data type. All column access methods in SDOResultSet use the flat model (see OpenEdge Development: Open Client Introduction and Programming ). The column is specified by name (
columnName) or number (columnIndex) and is set to the specified value (value):
void updateBigDecimal(intcolumnIndex, BigDecimalvalue)void updateBigDecimal(StringcolumnName, BigDecimalvalue)void updateBlob(intcolumnIndex, java.sql.Blobvalue)void updateBlob(StringcolumnName, java.sql.Blobvalue)void updateBoolean(intcolumnIndex, booleanvalue)void updateBoolean(StringcolumnName, booleanvalue)void updateBytes(intcolumnIndex, byte x[])void updateBytes(StringcolumnName, byte x[])void updateClob(intcolumnIndex, java.sql.Clobvalue)void updateClob(StringcolumnName, java.sql.Clobvalue)void updateDate(intcolumnIndex, java.sql.Datevalue)void updateDate(StringcolumnName, java.sql.Datevalue)void updateDouble(intcolumnIndex, doublevalue)void updateDouble(StringcolumnName, doublevalue)void updateInt(intcolumnIndex, intvalue)void updateInt(StringcolumnName, intvalue)void updateLong(intcolumnIndex, longvalue)void updateLong(StringcolumnName, longvalue)void updateNull(intcolumnIndex)void updateNull(StringcolumnName)void updateObject(intcolumnIndex, Objectvalue)void updateObject(StringcolumnName, Objectvalue)void updateString(intcolumnIndex, Stringvalue)void updateString(StringcolumnName, Stringvalue)void updateTimestamp(intcolumnIndex, java.sql.TimeStampvalue)void updateTimestamp(StringcolumnName, java.sql.TimeStampvalue)Some
java.util.Dateandjava.sql.Datemethods are being deprecated by JavaSoft in favor of using the more robustjava.util.GregorianCalendar. These are the methods that update column values with instances of this class:For more information on the mapping between 4GL and Java data types for SQL
ResultSetapplications, see Appendix C "Passing Temp-tables as SQL ResultSet Parameters."Inserting, deleting, and updating rows
The methods in Table 9–2 manage operations on rows in the SDOResultSet.
Table 9–2: Managing operations on SDOResultSet rows Method Description Returnstrueif the cursor is positioned on a deleted row, whether or not the deletion is sent to the AppServer because it does not make sense to allow the user to manipulate a row that is logically deleted.The only time the row is not also physically deleted on the AppServer is if you are using a batch update. For more information, see the "Using batch mode [extension]" section. Returnstrueif the cursor is positioned on an inserted row position and the row is not yet sent to the AppServer. Returnstrueif the cursor is positioned on a row that is modified but not yet sent to the AppServer. Cancelsthe updates by rolling back the effects of all method calls that updated column values. To cancel these updates, you must invoke this method before any call toupdateRow()orinsertRow(). Deletes the row in the current position and sends the delete request to the AppServer. Sends the newly created row to the AppServer. Moves the cursor from the insert row back to the current position. Moves the cursor to a staging position for creating a new row. Sends the updates for the current row to the AppServer.
Using extended transactions
As described earlier, by default, each row modification (row update, insertion, and deletion method) executes as a single transaction in the SmartDataObject. You can extend a transaction to include multiple rows using
Batchmode, where asendBatch()method applies a set of row updates as a single transaction (see the "Using batch mode [extension]" section). You also can explicitly manage a larger transaction on the AppServer remotely, using an automatic transaction.An automatic transaction allows you to remotely create a larger transaction within which all SmartDataObject transactions become nested as subtransactions. Using an automatic transaction, the Open Client application can start, commit, and roll back a single transaction by executing methods on a special ProcObject defined in the same AppObject that provides access to the corresponding SmartDataObject. The persistent procedure underlying this ProcObject supports specific functionality and must be available for execution on the AppServer to make an automatic transaction possible. Such a transaction can encompass the entire life of the SDOResultSet. For more information on automatic transactions, see OpenEdge Application Server: Developing AppServer Applications .
Note: You should callreOpenQuery()after an explicit transaction roll-back, to maintain a cache that is consistent with the database. ThereOpenQuery()method also can be desirable after committing a transaction containing inserted rows, so these rows are visible within the ResultSet. For more information, see the "Visibility of updates" section.Using batch mode [extension]
Batchmode allows an Open Client to send several updates to the AppServer in one transaction. Depending on your application requirements, this might be a better update strategy than generating a transaction for each update method:
- If your application requires user feedback for each update method applied, you generally must complete a transaction for each update method and
Batchmode is not appropriate.- If your application requires that a group of updates be applied and succeed together, you must group the updates into a single large transaction. You can do this by using an automatic transaction or by using
Batchmode. For information on automatic transactions, see OpenEdge Application Server: Developing AppServer Applications .- If your application has the option of applying several updates individually or as a group, you can generally increase performance dramatically by grouping the updates into a single large transaction using
Batchmode.- If your SDOResultSet is in
Statelessmode, you can apply modifications only underBatchmode.Table 9–3 lists the SDOResultSet methods that support
Batchmode.
Table 9–3: SDOResultSet methods that support Batch mode Method DescriptionUndoes all the modifications of the current batch.
Sends the current batch to the AppServer.
Sends the current batch to the AppServer, then reopens the ResultSet. In
Statelessmode, this method is more efficient than separately callingsendBatch()andreOpenQuery(). For more information, see the "Visibility of updates" section.Starts a batch session. All the modifications (column updates, deletions and insertions) are maintained locally. Calling this method if you have already called it and have not called
sendBatch()orcancelBatch()throws an Exception.Returns
Note: A row that is updated or deleted intrueif the SDOResultSet object is inBatchmode (that is, you have calledstartBatch()and have not yet calledsendBatch()orsendBatchandReopen()).Batchmode, and has not yet been sent to the AppServer (usingsendBatch()), cannot be refreshed usingrefreshRow(). Also, to save your changes locally in batch mode, you must still call the row update methods (for example,insertRow()orupdateRow()) even though, in this mode, your changes are not sent to the AppServer.
Visibility of updates
The visibility, from within the Open Client, of an update to the SDOResultSet object depends on whether the update is applied by:
The following rules determine the visibility of updates initiated by the Open Client:
Updates by external applications typically can occur on the data source that feeds the SDOResultSet. You can make any such updates visible to the Open Client application by calling
reOpenQuery(), which refreshes all data in the SDOResultSet. If you do not callreOpenQuery(), however, the following rules determine the visibility of updates from external applications:
- Column updates — The modification of a column by another application can be made visible by calling the
refreshRow()method.- Row inserts — Row inserts are not visible in
PREFETCHmode. In other scrolling modes, the visibility is determined by a combination of the underlying implementation of SmartDataObject and the 4GL query. The guideline is that the application should not make any assumptions unless it makes an explicit call toreOpenQuery().- Row deletion — Row deletions are not visible in
PREFETCHscrolling mode. In other scrolling modes, the visibility is determined by a combination of the underlying implementation of the SmartDataObject and the 4GL query. The guideline is that the application should not make any assumptions unless it makes an explicit call torefreshRow()orreOpenQuery(). In these cases, the specific row deletion or all the row deletions become visible, respectively.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |